<?php

/**
 * Created by PhpStorm.
 * User: M2
 * Date: 13-11-11
 * Time: 下午6:11
 */
class YlCommentTaglib {

    public function parse($content, $arr = array()) {
        if (stripos($content, 'yl:comment') !== false) {
            $matches = preg_parse($content, 'yl:comment');
            foreach ($matches as $match) {
                $type = getParseOneAttr($match, 'type');
                if (!empty($type)) {
                    switch (strtolower($type)) {
                        case 'username':
                            $text = $arr['author'];
                            break;
                        case 'ip':
                            $text = $arr['author_ip'];
                            break;
                        case 'datetime':
                            $text = date("Y-m-d", $arr['commenttime']);
                            break;
                        case 'content':
                            $text = $arr['content'];
                            break;
                        case 'id':
                            $text = $arr['id'];
                            break;
                        default:
                            $text = $arr[$type];
                    }
                }
                $content = str_replace($match, $text, $content);
            }
        }
        return $content;
    }

}
